package org.ilead.iserve.service.manager;

import java.util.List;

import org.ilead.iserve.dao.IUserPermissionDAO;
import org.ilead.iserve.model.Area;
import org.ilead.iserve.model.UserPermission;

public class UserPermissionManager {
	private static UserPermissionManager instance = new UserPermissionManager();
	private List<UserPermission> permissionList;
	private IUserPermissionDAO userPermissionDAO;
	
	private UserPermissionManager(){
	}
	
	public static UserPermissionManager getInstance(){
		return instance;
	}
	
	public void setUserPermissionDAO(IUserPermissionDAO userPermissionDAO) {
		this.userPermissionDAO = userPermissionDAO;
	}

	public List<UserPermission> getAll(){
		if(permissionList == null)
			permissionList = userPermissionDAO.findAll();
		return permissionList;
	}
	
	public String getPermissionById(int id){
		for (UserPermission per : permissionList){
			if(per.getId() == id){
				return per.getCode();
			}
		}
		return "1";
	}
}
